package com.wutu.nbyjk8.controller;


import com.alibaba.fastjson.JSONObject;
import com.wutu.nbyjk8.service.impl.EnergyForwarder;
import com.wutu.nbyjk8.service.impl.EnergyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RequestMapping(value = "/open/api/energy")
public class EnergyForwardController {

    @Autowired
    private EnergyForwarder energyForwarder;

    @Autowired
    EnergyService energyService;

    @PostMapping("/forward")
    public String forward(@RequestBody JSONObject jsonObject) {
        String restType = jsonObject.getString("restType");
        String restUrl = jsonObject.getString("restUrl");
        JSONObject restBody = jsonObject.getJSONObject("restBody");
        // 注意：restBody作为字符串传入，可以根据实际情况反序列化为对象
        final ResponseEntity<String> stringResponseEntity = energyForwarder.forwardRequest(restType, restUrl, restBody, energyService.getToken());
        return stringResponseEntity.getBody();
    }


}
